<template>
    <div>
        <x-input title="用户名称" placeholder="" v-model="username"></x-input>
        <x-button style="width:95%" type="primary" @click.native="modify">保存</x-button>
        <div>
            <span>我的权限</span>
        </div>
        <div v-if="roleShow">
            <span style="position:relative;top:30px;left:15px">{{rolelist}}</span>
            <x-button type="primary" style="position:relative;left:100px;width:25%" @click.native="close">取消</x-button>
        </div>
    </div>
</template>

<script>
    import {XInput,XButton} from 'vux'
    import user from '../../api/user.js'
    export default {
        components:{
            XInput,
            XButton
        },
        data(){
            return {
                username:'测试员工',
                rolelist:"",
                roleShow:true
            }
        },
        mounted(){
            var r = user.userinfo.usertype
            this.rolelist = r.replace("31","抽奖管理").replace("32","存酒管理").replace("33","优惠券管理")
            this.username = user.userinfo.username
            if(this.username == undefined){
                this.username = '测试员工'
            }
        },
        methods:{
            modify(){
                var openid = user.userinfo.openid
                this.$axios.get("/user/updateName?username="+this.username+"&openid="+openid)
                .then((ret)=>{
                    alert("修改完成")
                })
            },
            close(){
                this.$axios.get("/user/closeGrant?openid="+user.userinfo.openid)
                .then(()=>{
                    this.roleShow = false
                    alert("关闭成功")
                })
            }
        }
    }
</script>